package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.entity.beautyescort.EscortServerGroup;
import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.beautyescort.CrossBeautyEscortMgr;
import com.yanqu.road.server.manger.EscortServerGroupMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_BEAUTY_ESCORT_USER_DATA_SYNC, desc = "下发玩家信息")
public class CrossBeautyEscortSyncUserDataCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        BeautyEscortProto.BeautyEscortUserDataSyncMsg.Builder syncMsg = BeautyEscortProto.BeautyEscortUserDataSyncMsg.newBuilder();
        EscortServerGroup group = EscortServerGroupMgr.getServerGroupByServerId(serverId);
        if(group != null && group.getEscortState() == 1){
            syncMsg.setCrossOpen(true);
            syncMsg.setGroupId(group.getGroupId());
            syncMsg.addAllServerList(group.getServerList());
        }else {
            syncMsg.setCrossOpen(false);
            syncMsg.setGroupId((int)serverId);
            syncMsg.addServerList(serverId);
        }
        if(null == CrossBeautyEscortMgr.getEscortPlayer(serverId, packet.getPlayerId())){
            syncMsg.setInit(false);
        }else {
            syncMsg.setInit(true);
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_BEAUTY_ESCORT_USER_DATA_SYNC, syncMsg));
    }

    @Override
    public void sendData() {

    }
}
